package com.gensdai.leliang.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.gensdai.leliang.R;
import com.gensdai.leliang.entity.Call;
import com.gensdai.leliang.remoteInterface.URLConfig;

import java.util.List;

/**
 * Created by Administrator on 2017/6/2.
 */

public class IndentCall_list_adapter extends BaseAdapter {

    Context mContext;
    List<Call> list;
    Honder honder;
    deleteItem DI;

    public IndentCall_list_adapter(Context context, List<Call> list, deleteItem di) {
        mContext = context;
        this.list = list;
        DI = di;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            honder = new Honder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.indent_news_adapter, null);
            honder.time = (TextView) convertView.findViewById(R.id.time);
            honder.delete = (TextView) convertView.findViewById(R.id.delete);
            honder.wayBillNo = (TextView) convertView.findViewById(R.id.attributeNumber);
            honder.productName = (TextView) convertView.findViewById(R.id.proName);
            honder.dian = (ImageView) convertView.findViewById(R.id.dian);
            honder.logisticsCompany = (TextView) convertView.findViewById(R.id.logisticsCompany);
            honder.state = (TextView) convertView.findViewById(R.id.state);

            honder.img = (SimpleDraweeView) convertView.findViewById(R.id.indent_img);
            if (list.get(position).getProductPic().length() > 5) {
                Uri uri = Uri.parse(list.get(position).getProductPic());
                honder.img.setImageURI(uri);
            }
            convertView.setTag(honder);
        } else {
            honder = (Honder) convertView.getTag();
        }
        honder.time.setText(list.get(position).getTime());
        honder.wayBillNo.setText("订单编号：" + list.get(position).getWayBillNo());
        honder.productName.setText(list.get(position).getProductName());
        honder.logisticsCompany.setText("（" + list.get(position).getLogisticsCompany() + "）");
        honder.state.setText(list.get(position).getState());
        if (list.get(position).getCall_state().equals("0")) {
            honder.dian.setVisibility(View.VISIBLE);
        } else {
            honder.dian.setVisibility(View.GONE);
        }

        honder.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (DI != null) {
                    DI.delete(position);
                }
            }
        });

        return convertView;
    }

    public interface deleteItem {
        void delete(int position);
    }

    class Honder {

        TextView time;//时间
        TextView delete; //删除
        TextView wayBillNo; //商品编号
        TextView productName; //商品名
        TextView logisticsCompany; //运输方式
        TextView state; //状态
        ImageView dian; // 小红点
        SimpleDraweeView img; //商品图片
    }

}
